#include <string>
#include "scr_mouse.h"

bool SCRMouse::mCurrentStateA[SCR_MOUSE_BUTTON_SIZE];
bool SCRMouse::mPreviousStateA[SCR_MOUSE_BUTTON_SIZE];
int SCRMouse::m_X = 0;
int SCRMouse::m_Y = 0;

bool SCRMouse::IsPressed(const SCRMouseButton::Enum& Button)
{
	const int MaskedButton = Button & SCR_MOUSE_BUTTON_MASK;
	
	return mCurrentStateA[MaskedButton];
}

bool SCRMouse::IsReleased(const SCRMouseButton::Enum& Button)
{
	const int MaskedButton = Button & SCR_MOUSE_BUTTON_MASK;

	return !mCurrentStateA[MaskedButton] &&
		mPreviousStateA[MaskedButton];
}

bool SCRMouse::IsClicked(const SCRMouseButton::Enum& Button)
{
	const int MaskedButton = Button & SCR_MOUSE_BUTTON_MASK;

	return mCurrentStateA[MaskedButton] &&
		!mPreviousStateA[MaskedButton];
}

void SCRMouse::InitializeState()
{
	std::memset(mCurrentStateA, 0, SCR_MOUSE_BUTTON_SIZE * sizeof(bool));
	std::memset(mPreviousStateA, 0, SCR_MOUSE_BUTTON_SIZE * sizeof(bool));
}

void SCRMouse::UpdateState()
{
	std::memcpy(mPreviousStateA, mCurrentStateA, SCR_MOUSE_BUTTON_SIZE * sizeof(bool));
}
